package com.stars.home.utils;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.View;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
import com.stars.home.config.MIntentAction;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;

/**
 * 拍照/照片
 *
 * on 2020/9/16
 */
public class ChosePhotoUtils {


    public static void getChosePhoto(Context context, int maxPics) {
        getChosePhoto(context, maxPics, null);

    }

    public static void getChosePhoto(Context context, int maxPics, DialogInterface.OnDismissListener dismissListener) {

        new QMUIBottomSheet.BottomListSheetBuilder(context)
                .addItem("拍照")
                .addItem("照片")
                .setAllowDrag(true)
                .setGravityCenter(true)
                .setAddCancelBtn(true)
                .setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                    @Override
                    public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                        if (position == 0) {
                            PictureSelector.create((Activity) context)
                                    .openCamera(PictureMimeType.ofImage())
                                    .imageEngine(LoadEngin.INSTANCE) // Please refer to the Demo GlideEngine.java
                                    .forResult(MIntentAction.REQUEST_CODE_CAMERA);

                            dialog.dismiss();
                        } else {
                            //照片
                            PictureSelector.create((Activity) context)
                                    .openGallery(PictureMimeType.ofImage())
                                    .imageEngine(LoadEngin.INSTANCE)// 外部传入图片加载引擎，必传项
                                    .isMaxSelectEnabledMask(true)// 选择数到了最大阀值列表是否启用蒙层效果
                                    .maxSelectNum(maxPics)
                                    .selectionMode(PictureConfig.MULTIPLE)
                                    .isPreviewImage(true)// 是否可预览图片
                                    .isCompress(false)// 是否压缩
                                    .forResult(MIntentAction.REQUEST_CODE_IMG);
                            dialog.dismiss();
                        }
                    }
                })
                .setOnBottomDialogDismissListener(dismissListener)
                .build()
                .show();
    }


}
